const zlib = require('node:zlib')
const fs = require('node:fs')
const http = require('node:http')
// 压缩文件
// const readStream = fs.createReadStream("index.txt")
// const writeStream = fs.createWriteStream('index.txt.gz')
// readStream.pipe(zlib.createGzip()).pipe(writeStream)

// 解压缩文件
// const readStream = fs.createReadStream("index.txt.gz")
// const writeStream = fs.createWriteStream('index2.txt')
// readStream.pipe(zlib.createGunzip()).pipe(writeStream)


const server = http.createServer((req, res) => {
    const txt = '哈哈哈'.repeat(10000)
    res.setHeader('Content-type', 'text/plan;charset=utf-8')
    // res.end(txt)

    // res.setHeader('Content-Encoding', 'gzip')
    // let result = zlib.gzipSync(txt)
    // res.end(result)

    res.setHeader('Content-Encoding', 'deflate')
    let result = zlib.deflateSync(txt)
    res.end(result)

})

server.listen(3000,()=>{
    console.log('服务启动成功')
})
